<?php
namespace app\admin\controller;
use app\admin\model\HistoryPeripheral;
use app\admin\model\Performer;
use think\Request;

class SoftArticle extends Base
{
    protected function _initialize(){
        $this->checkLogin();
        $this->menuLoad();
    }
    public function index(){
        return $this->fetch('public/help');
    }

    public function companyHistoryList(){
        $historyPeripheral = new HistoryPeripheral();
        $where['type'] = 1;
        $rs = $historyPeripheral->getAll($where);
        $this->assign('rs',$rs);
        return $this->fetch();
    }

    public function addCompanyHistory(Request $request){
        if($request->post()){
            $data = $request->post();
            if($data['name'] =='' or $data['sort'] =='' or $data['img'] ==''){
                return $this->error('添加失败');
            }
            $historyPeripheral = new HistoryPeripheral();
            $rs = $historyPeripheral->add($data);
            if($rs){
                return $this->success('添加成功');
            }else{
                return $this->error('添加失败');
            }
        }
        return $this->fetch();
    }

    public function editCompanyHistory(Request $request){
        $historyPeripheral = new HistoryPeripheral();
        if($request->post()){
            $data = $request->post();
            $where['id'] = $data['id'];
            unset($data['id']);
            $rs = $historyPeripheral->edit($where,$data);
            if($rs){
                return $this->success('修改成功');
            }else{
                return $this->error('修改失败');
            }
        }

        $data = $request->get();
        $where['id'] = $data['id'];
        $rs = $historyPeripheral->getOne($where);
        $this->assign('rs',$rs);
        return $this->fetch();
    }

    public function peripheralFacilitiesList(){
        $historyPeripheral = new HistoryPeripheral();
        $where['type'] = 2;
        $rs = $historyPeripheral->getAll($where);
        unset($rs['content']);
        $this->assign('rs',$rs);
        return $this->fetch();
    }

    public function addPeripheralFacilities(Request $request){
        if($request->post()){
            $data = $request->post();
            $historyPeripheral = new HistoryPeripheral();
            $rs = $historyPeripheral->add($data);
            if($rs){
                return $this->success('添加成功');
            }else{
                return $this->error('添加失败');
            }
        }
        return $this->fetch();
    }

    public function editPeripheralFacilities(Request $request){
        $historyPeripheral = new HistoryPeripheral();
        if($request->post()){
            $data = $request->post();
            $where['id'] = $data['id'];
            unset($data['id']);
            $rs = $historyPeripheral->edit($where,$data);
            if($rs){
                return $this->success('修改成功');
            }else{
                return $this->error('修改失败');
            }
        }
        $data = $request->get();
        $where['id'] = $data['id'];
        $rs = $historyPeripheral->getOne($where);
        $this->assign('rs',$rs);
        return $this->fetch();
    }

    public function performerList(){
        $performer = new Performer();
        $where['id'] = ['neq',0];
        $rs = $performer->getAll($where);
        $this->assign('rs',$rs);
        return $this->fetch();
    }

    public function addPerformer(Request $request){
        if($request->post()){
            $data = $request->post();
            $performer = new Performer();
            $rs = $performer->add($data);
            if($rs){
                return $this->success('添加成功');
            }else{
                return $this->error('添加失败');
            }
        }
        return $this->fetch();
    }

    public function editPerformer(Request $request){
        $performer = new Performer();
        if($request->post()){
            $data = $request->post();
            $where['id'] = $data['id'];
            unset($data['id']);
            $rs = $performer->edit($where,$data);
            if($rs){
                return $this->success('修改成功');
            }else{
                return $this->error('修改失败');
            }
        }
        $data = $request->get();
        $where['id'] = $data['id'];
        $rs = $performer->getOne($where);
        $this->assign('rs',$rs);
        return $this->fetch();
    }
}